package com.it.emall.utils;

import java.util.HashMap;
import java.util.Map;

public class ResponseUtils {
    public static final int SUCCESS=0;
    public static final int INVALID_LOGIN=700;
    public static final int INVALID_TOKEN=501;
    public static final int INVALID_DEFAULT=400;

    /**
     * 成功响应
     * @param data 响应的核心数据
     * */

    public static Object ok(Object data){
        Map<String,Object> result=new HashMap<>();
        result.put("errno",SUCCESS);
        result.put("errmsg","成功");
        result.put("data",data);
        return result;
    }

    /**
     * 失败响应结果
     * errno 失败的错误码
     * errmsg 错误纤细描述
     * data 核心数据
     * */

    public static Object fail(int errno,String errmsg,Object data){
        Map<String,Object> result=new HashMap<>();
        result.put("errno",errno);
        result.put("errmsg",errmsg);
        result.put("data",data);
        return result;
    }

    public static Object fail(int errno,String errmsg){
        return fail(errno,errmsg,null);
    }
}
